package com.aps.common.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;

import java.time.LocalDateTime;

/**
 * 设备数据模型
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "设备数据模型")
public class EquipmentAbandoned {
    
    @NotBlank(message = "设备ID不能为空")
    @JsonProperty("equipmentId")
    @Schema(description = "设备ID", example = "EQ001")
    private String equipmentId;
    
    @NotBlank(message = "设备名称不能为空")
    @JsonProperty("equipmentName")
    @Schema(description = "设备名称", example = "注塑机A")
    private String equipmentName;
    
    @NotBlank(message = "设备类型不能为空")
    @JsonProperty("equipmentType")
    @Schema(description = "设备类型", example = "注塑机")
    private String equipmentType;
    
    @NotNull(message = "日产能不能为空")
    @JsonProperty("dailyCapacity")
    @Schema(description = "日产能")
    private TimeValue dailyCapacity;
    
    @NotNull(message = "效率系数不能为空")
    @DecimalMin(value = "0.0", message = "效率系数不能小于0")
    @DecimalMax(value = "1.0", message = "效率系数不能大于1")
    @JsonProperty("efficiencyFactor")
    @Schema(description = "效率系数", example = "0.85")
    private Double efficiencyFactor;
    
    @NotBlank(message = "维护计划不能为空")
    @JsonProperty("maintenanceSchedule")
    @Schema(description = "维护计划", example = "每月1号")
    private String maintenanceSchedule;
    
    @NotBlank(message = "设备状态不能为空")
    @JsonProperty("status")
    @Schema(description = "设备状态", example = "正常")
    private String status;
    
    /**
     * 时间值模型
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "时间值模型")
    public static class TimeValue {
        @Positive(message = "时间值必须为正数")
        @JsonProperty("value")
        @Schema(description = "时间值", example = "8.0")
        private Double value;
        
        @NotBlank(message = "时间单位不能为空")
        @JsonProperty("unit")
        @Schema(description = "时间单位", example = "小时")
        private String unit;
    }
    
    /**
     * 设备状态枚举
     */
    @Schema(description = "设备状态枚举")
    public enum Status {
        NORMAL("正常"),
        MAINTENANCE("维护中"),
        BREAKDOWN("故障"),
        IDLE("闲置");
        
        private final String description;
        
        Status(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }


    /**
     * 构造函数
     *
     * @param id 设备ID
     * @param initialAvailableTime 初始可用时间
     */
    public EquipmentAbandoned(String id, LocalDateTime initialAvailableTime) {
        if (id == null || id.trim().isEmpty()) {
            throw new IllegalArgumentException("设备ID不能为空");
        }
        if (initialAvailableTime == null) {
            throw new IllegalArgumentException("初始可用时间不能为空");
        }

        this.equipmentId = id;
//        this.nextAvailableTime = initialAvailableTime;
//        this.scheduledIntervals = new ArrayList<>();
    }
} 